<?php
/* SVN FILE: $Id: setup.php 229 2009-09-25 23:07:14Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Manage Plugins
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 229 $
* @lastrevision $Date: 2009-09-25 23:07:14 +0000 (Fri, 25 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-25 23:07:14 +0000 (Fri, 25 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_admin/plugin/setup.php $
*/


if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class admin_ibmarket_plugin_setup extends ipsCommand
{
	/**
	 * Skin object
	 *
	 * @access	private
	 * @var		object			Skin templates
	 */
	private $html;
	
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		$this->registry->getClass('class_permissions')->checkPermissionAutoMsg( 'manage_plugin' );
		
		$this->html = $this->registry->output->loadTemplate('cp_skin_plugins');
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'admin_market', 'admin_plugins' ) );
		
		require_once( IPS_KERNEL_PATH . 'classXML.php' );
		$xml = new classXML( $this->settings['gb_char_set'] );
		
		$plugins = array();
		foreach(new DirectoryIterator(IPSLib::getAppDir('ibmarket')."/plugins/") as $directory)
		{
			if($directory->isDot() || !$directory->isDir() || !file_exists(IPSLib::getAppDir('ibmarket')."/plugins/".$directory."/xml/information.xml"))
			{
				continue;
			}
			
			$xml->load( IPSLib::getAppDir('ibmarket')."/plugins/".$directory."/xml/information.xml" );
			
			// How not use use the array
			if(!$data = $xml->fetchElements('data'))
			{
				continue;
			}
			$data = $data->item(0);
			
			$plugins[$directory.""] = array(
												$xml->fetchItem($xml->fetchElements('name',$data)->item(0)),
												$xml->fetchItem($xml->fetchElements('description',$data)->item(0)),
												$xml->fetchItem($xml->fetchElements('author',$data)->item(0)),
											);
		}
		foreach($this->caches['market_plugin'] as $plugin)
		{
			unset($plugins[$plugin['directory']]);
		}
		
		$this->registry->output->html = $this->html->managePlugins( $plugins );
		
		$this->registry->getClass('output')->html_main .= $this->registry->getClass('output')->global_template->global_frame_wrapper();
		$this->registry->getClass('output')->sendOutput();
	}
}